﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace SmoothControls
{
	public partial class MenuItem : UserControl, IExtendedListItem
	{

		public String Source { get; set; }
		public String Username { get; set; }
		public String Content { get; set; }
		public Image Avatar { get; set; }
		public String TimeStamp { get; set; }
		public Boolean IsSelected { get; set; }
		public Object Value { get; set;}
		public MenuItem()
		{

			InitializeComponent();
		}

		public MenuItem( String username, String source, String content, String timestamp, Object value, Image avatar )
		{
			InitializeComponent();
			this.Username = username;
			this.Source = source;
			this.Content = content;
			this.TimeStamp = timestamp;
			this.Avatar = avatar;
			this.Value = value;

		}

		public MenuItem( String username, String source, String content, String timestamp, Image avatar )
		{
			InitializeComponent();
			this.Username = username;
			this.Source = source;
			this.Content = content;
			this.TimeStamp = timestamp;
			this.Avatar = avatar;

		}


		public MenuItem( String username, String source, String content, String timestamp )
		{
			InitializeComponent();
			this.Username = username;
			this.Source = source;
			this.Content = content;
			this.TimeStamp = timestamp;

		}

		protected override void OnPaint( PaintEventArgs e )
		{
			using ( Image flickerBuffer = new Bitmap( this.Width, this.Height ) )
			{
				using ( Graphics flickerGraphics = Graphics.FromImage( flickerBuffer ) )
				{
					flickerGraphics.Clear( Color.Black );
					//CONTENT
					flickerGraphics.FillRectangle( new SolidBrush( Color.Black ), e.ClipRectangle );
					flickerGraphics.DrawLine( new Pen( Color.Orange ), 0, this.Height - 1, this.Width, this.Height - 1 );
					if ( IsSelected )
					{
						//e.Graphics.FillRectangle(new SolidBrush(Color.Orange), e.ClipRectangle);
						Gradient.GradientFill.Fill( flickerGraphics, e.ClipRectangle, Color.Black, Color.Orange, Gradient.GradientFill.FillDirection.TopToBottom );

					}
					if ( Avatar != null )
					{
						flickerGraphics.DrawImage( Avatar, 3, 3, new Rectangle( 3, 3, 65, 67 ), GraphicsUnit.Pixel );
					}
					flickerGraphics.DrawString( this.Content, new Font( FontFamily.GenericSansSerif, 10f, FontStyle.Regular ), new SolidBrush( Color.White ), new RectangleF( 73f, 24f, 163f, 46f ) );
					SizeF stampSize = flickerGraphics.MeasureString(this.TimeStamp, new Font( FontFamily.GenericSansSerif, 8f, FontStyle.Regular ));
					flickerGraphics.DrawString( this.TimeStamp, new Font( FontFamily.GenericSansSerif, 8f, FontStyle.Regular ), new SolidBrush( Color.White ), new RectangleF( 135f, 70f, stampSize.Width, 20f ) );
					flickerGraphics.DrawString( this.Source, new Font( FontFamily.GenericSansSerif, 8f, FontStyle.Regular ), new SolidBrush( Color.White ), new RectangleF( 0f, 70f, 100f, 20f ) );
					//END CONTENT
					e.Graphics.DrawImage( flickerBuffer, 0, 0 );
				}
			}

		}

		protected override void OnPaintBackground( PaintEventArgs e )
		{
			//Do Nothing
		}
		#region IExtendedListItem Members

		public void SelectedChanged( bool isSelected )
		{
			this.IsSelected = isSelected;
		}

		public void PositionChanged( int index )
		{
			//throw new NotImplementedException();
		}

		#endregion
	}
}
